<!DOCTYPE html>
<html>

<head>
    <title>我的奖励</title>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1,user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="telephone=no" name="format-detection">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/reset.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/flex.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/dropload.css">
    <link rel="stylesheet" type="text/css" href="/resource/web/css/accounts-ticket.css">
    <script type="text/javascript" src="/resource/web/js/flexible.js"></script>
    <script type="text/javascript" src="/resource/web/js/jquery-1.11.1.min.js"></script>
</head>

<body>
    <div class="mod-tit">
        <div class="title">
            <p>我的奖励</p>
            <a href="javascript:;"  onClick="location.href='/Web/user_accounts'"><img class="back" src="/resource/web/img/newhead/path_7_copy.png"></a>
        </div>
        <div class="mod-tab">
            <div class="acc-tab tcf-flex tcf-justify-center">
                <a href="/Web/account_myredcon.html"><div class="acct-red accred">我的红包</div></a>
                <a href="/Web/account_ticket.html"><div class="acct-tick">我的加息券</div></a>
            </div>
        </div>
    </div>
    <div class="linemargin"></div>
    <!-- hongbao use -->
    <div class="mod-red content">
        <div class="my-ticket2 list" >
        </div>
    </div>

    <!-- 无红包无加息券显示 -->
    <div class="my-ticket3" >
        <p><img src="/resource/web/img/account/no_msg.png"></p>
    </div>
<script src="/resource/web/js/dropload.min.js"></script>
<script type="text/javascript">
    function getLocalTime(nS) {
        var dateStr=new Date(parseInt(nS) * 1000).toLocaleDateString();
        dateStr=dateStr.replace(/年|月/g, "/").replace(/日/g,"");
        var month = (new Date(dateStr)).getMonth() + 1;
        var year = (new Date(dateStr)).getFullYear();
        var date = (new Date(dateStr)).getDate();
        if (month < 10) {
            month = '0' + month;
        }
        if (date < 10) {
            date = '0' + date;
        }
        return year+"-"+month+"-"+date;
    }
    $(function(){
        // 页数
        var page = 0;
        // 每页展示5个
        //var size = 10;
        // dropload
        $('.content').dropload({
            scrollArea : window,
            loadDownFn : function(me){
                page++;
                var result = '';
                $.ajax({
                    type: 'GET',
                    processData: false,//https://www.gangpiaowang.com
                    url: 'https://www.gangpiaowang.com/Web/account_myred.html?page='+page,
                    dataType: 'json',
                    success: function(data){
                        var arrLen = data.length;
                        var arrlist = data;
                        console.log(arrLen);
                        if(arrLen > 0){
                            $(".my-ticket3").hide();
                            for(var i=0; i<arrLen; i++){
                                console.log( arrlist[i] );
                                //立即使用
                                var time = arrlist[i].due_time;
                                if( arrlist[i].status == "AVAILABLE" ){
                                    result +=   '<div class="myr"><div class="myr-l">'
                                            +'<p><span>'+arrlist[i].amount+'</span>元</p></div><ul class="myr-r">'
                                            +'<li class="myr-tit">单笔投资满<span>'+arrlist[i].restrict_amount+'元</span><br />仅限≥'+arrlist[i].limit+'天投资项目</li>'
                                            +'<li class="myr-tim">有效期至'+getLocalTime(time)+'</li>'
                                            +'<a href="#0"><li class="myr-btn">立即使用</li></a>'
                                            +'</ul></div>'
                                }else if ( arrlist[i].status == "HAS_USED" ){
                                    result +=   '<div class="myr myr2"><div class="myr-l">'
                                            +'<p><span>'+arrlist[i].amount+'</span>元</p></div><ul class="myr-r">'
                                            +'<li class="myr-tit">单笔投资满<span>'+arrlist[i].restrict_amount+'元</span><br />仅限≥'+arrlist[i].limit+'天投资项目</li>'
                                            +'<li class="myr-tim">有效期至'+getLocalTime(time)+'</li>'
                                            +'<a href="#0"><li class="myr-btn">已使用</li></a>'
                                            +'</ul></div>'
                                }else  if ( arrlist[i].status == "PAST_DUE" ) {
                                    result +=   '<div class="myr myr2"><div class="myr-l">'
                                            +'<p><span>'+arrlist[i].amount+'</span>元</p></div><ul class="myr-r">'
                                            +'<li class="myr-tit">单笔投资满<span>'+arrlist[i].restrict_amount+'元</span><br />仅限≥'+arrlist[i].limit+'天投资项目</li>'
                                            +'<li class="myr-tim">有效期至'+getLocalTime(time)+'</li>'
                                            +'<a href="#0"><li class="myr-btn">已过期</li></a>'
                                            +'</ul></div>'
                                }
                            }
                            // 如果没有数据
                        }else{
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        $('.list').append(result);
                        me.resetload();
                        // 为了测试，延迟1秒加载
                        /*setTimeout(function(){
                         // 插入数据到页面，放到最后面
                         $('.lists').append(result);
                         // 每次数据插入，必须重置
                         me.resetload();
                         },1000);*/
                    },
                    error: function(xhr, type){
                        console.log('Ajax error!');
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
            }
        });
    });
</script>
</body>

</html>
